package game.leon.engine.net.example.server;

import game.leon.engine.net.example.server.exception.MessageLoopStopException;
import game.leon.engine.utils.LinkedNode;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

/**
 * User: bianpeng
 * Date: 11-12-27
 */
@Component
public class ServerMessageConsumer {
    private Logger logger = Logger.getLogger(getClass());
    private void execute(Message message) {
        // TODO: 处理每一个事件, 这里是单线程的
        message.getSession().getIoSession().write(message.getRawMessage());

        logger.info(String.format("[server] user=%d, message=%d",
                message.getRawMessage().getUserId(),
                message.getRawMessage().getMessage()));
    }
    public void execute(LinkedNode<Message> messageList) throws MessageLoopStopException {
        while (messageList != null) {
            execute(messageList.getItem());
            messageList = messageList.getNext();
        }
    }
}
